package main

import (
	"os"
	"sync"
	"fmt"
	"net/http"
)

var wg sync.WaitGroup

func main() {
	var urls = []string {
		"baidu.com",
		"51cto.com",
		"go-zh.org",
	}
	for _, url := range urls {
		wg.Add(1)  // 每开一个goroutine，计数加1
		go func(url string) {
			defer wg.Done()  // 退出时计数减1
			resp, err := http.Head("http://" + url)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%s Head ERROR: %v", url, err)
				return
			}
			fmt.Println(*resp)
		}(url)
	}
	wg.Wait()  // 在这里等待，所有任务完成，才继续
	fmt.Println("All Requests Down")
}